📄 btctl.c
字号:
/* Affix - Bluetooth Protocol Stack for Linux Copyright (C) 2001 - 2004 Nokia Corporation Original Author: Dmitry Kasatkin <dmitry.kasatkin@nokia.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* $Id: btctl.c,v 1.190 2004/05/25 11:51:34 kassatki Exp $ btctl - driver control program Fixes: Dmitry Kasatkin <dmitry.kasatkin@nokia.com>*/#include <affix/config.h>#include <sys/socket.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/time.h>#include <sys/resource.h>#include <sys/errno.h>#include <fcntl.h>#include <unistd.h>#include <syslog.h>#include <signal.h>#include <stdlib.h>#include <stdio.h>#include <stdarg.h>#include <getopt.h>#include <string.h>#include <termios.h>#include <affix/bluetooth.h>#include <affix/btcore.h>#include <affix/utils.h>#include "btctl.h"int nameset;int showall = 0;int uart_rate = -1;char *uart_map = "/etc/affix/device.map";#if defined(CONFIG_AFFIX_BT_1_2)int cmd_create_connection_cancel(struct command *cmd){ int err, fd; BD_ADDR bda; if (__argv[optind] == NULL) { printf("Bluetooth address missed\n"); return -1; } err = btdev_get_bda(&bda, __argv[optind]); if (err) { printf("Wrong address format\n"); return 1; } fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } err = HCI_CreateConnectionCancel(fd, &bda); hci_close(fd); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("Create Connection cancelled on BT address: %s\n", bda2str(&bda)); pause(); return 0;}int cmd_remote_name_cancel (struct command *cmd){ int err, fd; BD_ADDR bda; if (__argv[optind] == NULL) { printf("Bluetooth address missed\n"); return -1; } err = btdev_get_bda(&bda, __argv[optind]); if (err) { printf("Wrong address format\n"); return 1; } fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return fd; } err = HCI_RemoteNameRequestCancel(fd, &bda); hci_close(fd); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("Remote name request CANCELED !\n"); return 0;}int cmd_lmp_handle(struct command *cmd){ int err,fd; int handle; __u8 lmp_handle = 0; BD_ADDR bda; if (__argv[optind] == NULL) { print_usage(cmd); return -1; } err = btdev_get_bda(&bda, __argv[optind]); if (err) { printf("Wrong address format\n"); return 1; } fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } handle = hci_get_conn(fd, &bda); if (handle < 0) { printf("Connection not found\n"); return 1; } err = HCI_ReadLMPHandle(fd, handle, &lmp_handle); hci_close(fd); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("LMP handle for %s connection: %x",bda2str(&bda), lmp_handle); return 0;}int cmd_remote_extended_features(struct command *cmd){ int err,fd,handle; __u8 maximum_page_number = 0,page_number = 0; __u8 extended_lmp_features[8]; BD_ADDR bda; if (__argv[optind] == NULL) { print_usage(cmd); return -1; } err = btdev_get_bda(&bda, __argv[optind]); if (err) { printf("Wrong address format\n"); return 1; } if (__argv[optind+1] != NULL) { page_number = atoi(__argv[optind+1]); } fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } handle = hci_get_conn(fd, &bda); if (handle < 0) { printf("Connection not found\n"); return 1; } err = HCI_ReadRemoteExtendedFeatures(fd, handle, page_number,&maximum_page_number,extended_lmp_features); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("Extended Features for %s :\n Maximum Page Number : %x\n LMP Features byte 0: %x, byte 1: %x, byte 2: %x, byte 3: %x, byte 4: %x, byte 5 : %x, byte 6: %x, byte 7: %x \n",bda2str(&bda),maximum_page_number,extended_lmp_features[0],extended_lmp_features[1],extended_lmp_features[2],extended_lmp_features[3],extended_lmp_features[4],extended_lmp_features[5],extended_lmp_features[6],extended_lmp_features[7]); hci_close(fd); return 0;}// Link Policy Commandsint cmd_link_policy_settings (struct command *cmd){ int err,fd; __u16 Default_Link_Policy_Settings; fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } if (cmd->cmd) { if (__argv[optind] == NULL){ print_usage(cmd); return -1; } Default_Link_Policy_Settings = atoi(__argv[optind]); err = HCI_WriteDefaultLinkPolicySettings(fd,Default_Link_Policy_Settings); } else { err = HCI_ReadDefaultLinkPolicySettings(fd,&Default_Link_Policy_Settings); } hci_close(fd); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("Writting Default Link Policy Settings (%x) DONE.\n",Default_Link_Policy_Settings); return 0;}int cmd_flow_specification(struct command *cmd){ int fd,err,handle; BD_ADDR bda; HCI_FLOW Requested_Flow, Completed_Flow; if (__argc < 7) { print_usage(cmd); return -1; } err = btdev_get_bda(&bda, __argv[optind]); if (err) { printf("Wrong address format\n"); return 1; } Requested_Flow.Flags = 0; // Reserved if ((Requested_Flow.Flow_direction = atoi(__argv[optind+1])) > 1) { printf("Wrong Flow direction. Valid values: 0 -> Outgoing Flow, 1 -> Incoming Flow.\n"); return 1; } if ((Requested_Flow.Service_Type = atoi(__argv[optind+2])) > 2) { printf ("Wrong Service Type: Valid values: 0 -> No traffic, 1 -> Best Effort, 2 -> Guaranteed\n"); return 1; } Requested_Flow.Token_Rate = atoi(__argv[optind+3]); Requested_Flow.Token_Bucket_Size = atoi(__argv[optind+4]); Requested_Flow.Peak_Bandwidth = atoi(__argv[optind+5]); Requested_Flow.Access_Latency = atoi(__argv[optind+6]); fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } handle = hci_get_conn(fd, &bda); if (handle < 0) { printf("Connection not found\n"); return 1; } err = HCI_Flow_Specification( fd, handle, &Requested_Flow, &Completed_Flow); hci_close(fd); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("Flow specification: ->Flow_direction: %x\n ->Service_Type: %x\n ->Token_Rate: %x\n ->Token_Bucket_Size: %x\n ->Peak_Bandwidth: %x\n Access_Latency: %x\n", Completed_Flow.Flow_direction, Completed_Flow.Service_Type, Completed_Flow.Token_Rate, Completed_Flow.Token_Bucket_Size, Completed_Flow.Peak_Bandwidth, Completed_Flow.Access_Latency); return 0;}int cmd_afh_host_channel(struct command *cmd){ int fd,err,i; __u32 value; __u8 channels[12]; for (i=0;i<3;i++) { if (sscanf(__argv[optind+i],"%x",&value)){ print_usage(cmd); return -1; } channels[i*4] = value; channels[i*4 + 1] = value>>8; channels[i*4 + 2] = value>>16; channels[i*4 + 3] = value>>24; } fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } err = HCI_SetAFHHostChannelClassification(fd,channels); hci_close(fd); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("Done.\n"); return 0;}int cmd_inquiry_scan_type(struct command *cmd){ int err,fd; __u8 inquiry_scan_type = 0; fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } if (cmd->cmd) { // If Write Inwuiry scan command then read value from command line. if ((__argv[optind]==NULL) || ((inquiry_scan_type = atoi(__argv[optind])) > 1)) { print_usage(cmd); return -1; } err = HCI_WriteInquiryScanType(fd,inquiry_scan_type); } else { err = HCI_ReadInquiryScanType(fd,&inquiry_scan_type); } hci_close(fd); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("Inquiry Scan Type: %x\n",inquiry_scan_type); return 0;}int cmd_inquiry_mode(struct command *cmd){ int err,fd; __u8 inquiry_mode = 0; fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } if (cmd->cmd) { // If write inquiry mode the read value from command line. if ((__argv[optind]==NULL) || ((inquiry_mode = atoi(__argv[optind])) > 1)) { print_usage(cmd); return -1; } err = HCI_WriteInquiryMode(fd,inquiry_mode); } else { err = HCI_ReadInquiryMode(fd,&inquiry_mode); } hci_close(fd); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("Inquiry Mode: %x\n",inquiry_mode); return 0; }int cmd_page_scan_type(struct command *cmd){ int err,fd; __u8 page_scan_type = 0; fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } if (cmd->cmd) { if ((__argv[optind]==NULL) || ((page_scan_type = atoi(__argv[optind])) > 1)) { print_usage(cmd); return -1; } err = HCI_WritePageScanType(fd,page_scan_type); } else { err = HCI_ReadPageScanType(fd,&page_scan_type); } hci_close(fd); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("Page Scan Type: %x\n",page_scan_type); return 0;}int cmd_afh_cam(struct command *cmd){ int err,fd; __u8 AFH_Channel_Assessment_Mode = 0; fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } if (cmd->cmd) { if ((__argv[optind]==NULL) || ((AFH_Channel_Assessment_Mode = atoi(__argv[optind])) > 1)) { print_usage(cmd); return -1; } err = HCI_WriteAFHChannelAssessmentMode(fd,AFH_Channel_Assessment_Mode); } else { err = HCI_ReadAFHChannelAssessmentMode(fd,&AFH_Channel_Assessment_Mode); } hci_close(fd); if (err) { fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("AFH Channel Assessment Mode: %x\n",AFH_Channel_Assessment_Mode); return 0;}int cmd_local_extended_features(struct command *cmd){ int err,fd; __u8 page_number,maximum_page_number; __u64 extended_lmp_features; if (__argv[optind]==NULL) { print_usage(cmd); return -1; } page_number = atoi(__argv[optind]); fd = hci_open(btdev); if (fd < 0) { printf("Unable to open device %s: %s\n", btdev, strerror(errno)); return -1; } err = HCI_ReadLocalExtendedFeatures(fd, &page_number, &maximum_page_number, &extended_lmp_features); hci_close(fd); if (err){ fprintf(stderr, "%s\n", hci_error(err)); exit(1); } printf("Read Local Extended Features:\n ->Page Number: %x\n ->Maximum Page Number: %x\n Extended_LMP_Features: %llx\n",page_number,maximum_page_number,extended_lmp_features); return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -