⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hci.c

📁 Linux下蓝牙探测工具
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * *  BlueZ - Bluetooth protocol stack for Linux * *  Copyright (C) 2000-2002  Maxim Krasnyansky <maxk@qualcomm.com> *  Copyright (C) 2003-2007  Marcel Holtmann <marcel@holtmann.org> * * *  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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA * */#ifdef HAVE_CONFIG_H#include <config.h>#endif#include <stdio.h>#include <errno.h>#include <ctype.h>#include <unistd.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <bluetooth/bluetooth.h>#include <bluetooth/hci.h>#include <bluetooth/hci_lib.h>#include "parser.h"static uint16_t manufacturer = DEFAULT_COMPID;static inline uint16_t get_manufacturer(void){	return (manufacturer == DEFAULT_COMPID ? parser.defcompid : manufacturer);}#define EVENT_NUM 61static char *event_str[EVENT_NUM + 1] = {	"Unknown",	"Inquiry Complete",	"Inquiry Result",	"Connect Complete",	"Connect Request",	"Disconn Complete",	"Auth Complete",	"Remote Name Req Complete",	"Encrypt Change",	"Change Connection Link Key Complete",	"Master Link Key Complete",	"Read Remote Supported Features",	"Read Remote Ver Info Complete",	"QoS Setup Complete",	"Command Complete",	"Command Status",	"Hardware Error",	"Flush Occurred",	"Role Change",	"Number of Completed Packets",	"Mode Change",	"Return Link Keys",	"PIN Code Request",	"Link Key Request",	"Link Key Notification",	"Loopback Command",	"Data Buffer Overflow",	"Max Slots Change",	"Read Clock Offset Complete",	"Connection Packet Type Changed",	"QoS Violation",	"Page Scan Mode Change",	"Page Scan Repetition Mode Change",	"Flow Specification Complete",	"Inquiry Result with RSSI",	"Read Remote Extended Features",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Synchronous Connect Complete",	"Synchronous Connect Changed",	"Sniff Subrate",	"Extended Inquiry Result",	"Encryption Key Refresh Complete",	"IO Capability Request",	"IO Capability Response",	"User Confirmation Request",	"User Passkey Request",	"Remote OOB Data Request",	"Simple Pairing Complete",	"Unknown",	"Link Supervision Timeout Change",	"Enhanced Flush Complete",	"Unknown",	"User Passkey Notification",	"Keypress Notification",	"Remote Host Supported Features Notification",};#define CMD_LINKCTL_NUM 52static char *cmd_linkctl_str[CMD_LINKCTL_NUM + 1] = {	"Unknown",	"Inquiry",	"Inquiry Cancel",	"Periodic Inquiry Mode",	"Exit Periodic Inquiry Mode",	"Create Connection",	"Disconnect",	"Add SCO Connection",	"Create Connection Cancel",	"Accept Connection Request",	"Reject Connection Request",	"Link Key Request Reply",	"Link Key Request Negative Reply",	"PIN Code Request Reply",	"PIN Code Request Negative Reply",	"Change Connection Packet Type",	"Unknown",	"Authentication Requested",	"Unknown",	"Set Connection Encryption",	"Unknown",	"Change Connection Link Key",	"Unknown",	"Master Link Key",	"Unknown",	"Remote Name Request",	"Remote Name Request Cancel",	"Read Remote Supported Features",	"Read Remote Extended Features",	"Read Remote Version Information",	"Unknown",	"Read Clock Offset",	"Read LMP Handle",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Setup Synchronous Connection",	"Accept Synchronous Connection",	"Reject Synchronous Connection",	"IO Capability Request Reply",	"User Confirmation Request Reply",	"User Confirmation Request Negative Reply",	"User Passkey Request Reply",	"User Passkey Request Negative Reply",	"Remote OOB Data Request Reply",	"Unknown",	"Unknown",	"Remote OOB Data Request Negative Reply",	"IO Capability Request Negative Reply",};#define CMD_LINKPOL_NUM 17static char *cmd_linkpol_str[CMD_LINKPOL_NUM + 1] = {	"Unknown",	"Hold Mode",	"Unknown",	"Sniff Mode",	"Exit Sniff Mode",	"Park State",	"Exit Park State",	"QoS Setup",	"Unknown",	"Role Discovery",	"Unknown",	"Switch Role",	"Read Link Policy Settings",	"Write Link Policy Settings",	"Read Default Link Policy Settings",	"Write Default Link Policy Settings",	"Flow Specification",	"Sniff Subrating",};#define CMD_HOSTCTL_NUM 95static char *cmd_hostctl_str[CMD_HOSTCTL_NUM + 1] = {	"Unknown",	"Set Event Mask",	"Unknown",	"Reset",	"Unknown",	"Set Event Filter",	"Unknown",	"Unknown",	"Flush",	"Read PIN Type ",	"Write PIN Type",	"Create New Unit Key",	"Unknown",	"Read Stored Link Key",	"Unknown",	"Unknown",	"Unknown",	"Write Stored Link Key",	"Delete Stored Link Key",	"Write Local Name",	"Read Local Name",	"Read Connection Accept Timeout",	"Write Connection Accept Timeout",	"Read Page Timeout",	"Write Page Timeout",	"Read Scan Enable",	"Write Scan Enable",	"Read Page Scan Activity",	"Write Page Scan Activity",	"Read Inquiry Scan Activity",	"Write Inquiry Scan Activity",	"Read Authentication Enable",	"Write Authentication Enable",	"Read Encryption Mode",	"Write Encryption Mode",	"Read Class of Device",	"Write Class of Device",	"Read Voice Setting",	"Write Voice Setting",	"Read Automatic Flush Timeout",	"Write Automatic Flush Timeout",	"Read Num Broadcast Retransmissions",	"Write Num Broadcast Retransmissions",	"Read Hold Mode Activity ",	"Write Hold Mode Activity",	"Read Transmit Power Level",	"Read Synchronous Flow Control Enable",	"Write Synchronous Flow Control Enable",	"Unknown",	"Set Host Controller To Host Flow Control",	"Unknown",	"Host Buffer Size",	"Unknown",	"Host Number of Completed Packets",	"Read Link Supervision Timeout",	"Write Link Supervision Timeout",	"Read Number of Supported IAC",	"Read Current IAC LAP",	"Write Current IAC LAP",	"Read Page Scan Period Mode",	"Write Page Scan Period Mode",	"Read Page Scan Mode",	"Write Page Scan Mode",	"Set AFH Host Channel Classification",	"Unknown",	"Unknown",	"Read Inquiry Scan Type",	"Write Inquiry Scan Type",	"Read Inquiry Mode",	"Write Inquiry Mode",	"Read Page Scan Type",	"Write Page Scan Type",	"Read AFH Channel Assessment Mode",	"Write AFH Channel Assessment Mode",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Unknown",	"Read Extended Inquiry Response",	"Write Extended Inquiry Response",	"Refresh Encryption Key",	"Unknown",	"Read Simple Pairing Mode",	"Write Simple Pairing Mode",	"Read Local OOB Data",	"Read Inquiry Response Transmit Power Level",	"Write Inquiry Response Transmit Power Level",	"Read Default Erroneous Data Reporting",	"Write Default Erroneous Data Reporting",	"Unknown",	"Unknown",	"Unknown",	"Enhanced Flush"	"Unknown",};#define CMD_INFO_NUM 9static char *cmd_info_str[CMD_INFO_NUM + 1] = {	"Unknown",	"Read Local Version Information",	"Read Local Supported Commands",	"Read Local Supported Features",	"Read Local Extended Features",	"Read Buffer Size",	"Unknown",	"Read Country Code",	"Unknown",	"Read BD ADDR",};#define CMD_STATUS_NUM 7static char *cmd_status_str[CMD_STATUS_NUM + 1] = {	"Unknown",	"Read Failed Contact Counter",	"Reset Failed Contact Counter",	"Read Link Quality",	"Unknown",	"Read RSSI",	"Read AFH Channel Map",	"Read Clock",};#define CMD_TESTING_NUM 4static char *cmd_testing_str[CMD_TESTING_NUM + 1] = {	"Unknown",	"Read Loopback Mode",	"Write Loopback Mode",	"Enable Device Under Test mode",	"Unknown",};#define ERROR_CODE_NUM 56static char *error_code_str[ERROR_CODE_NUM + 1] = {	"Success",	"Unknown HCI Command",	"Unknown Connection Identifier",	"Hardware Failure",	"Page Timeout",	"Authentication Failure",	"PIN or Key Missing",	"Memory Capacity Exceeded",	"Connection Timeout",	"Connection Limit Exceeded",	"Synchronous Connection to a Device Exceeded",	"ACL Connection Already Exists",	"Command Disallowed",	"Connection Rejected due to Limited Resources",	"Connection Rejected due to Security Reasons",	"Connection Rejected due to Unacceptable BD_ADDR",	"Connection Accept Timeout Exceeded",	"Unsupported Feature or Parameter Value",	"Invalid HCI Command Parameters",	"Remote User Terminated Connection",	"Remote Device Terminated Connection due to Low Resources",	"Remote Device Terminated Connection due to Power Off",	"Connection Terminated by Local Host",	"Repeated Attempts",	"Pairing Not Allowed",	"Unknown LMP PDU",	"Unsupported Remote Feature / Unsupported LMP Feature",	"SCO Offset Rejected",	"SCO Interval Rejected",	"SCO Air Mode Rejected",	"Invalid LMP Parameters",	"Unspecified Error",	"Unsupported LMP Parameter Value",	"Role Change Not Allowed",	"LMP Response Timeout",	"LMP Error Transaction Collision",	"LMP PDU Not Allowed",	"Encryption Mode Not Acceptable",	"Link Key Can Not be Changed",	"Requested QoS Not Supported",	"Instant Passed",	"Pairing with Unit Key Not Supported",	"Different Transaction Collision",	"Reserved",	"QoS Unacceptable Parameter",	"QoS Rejected",	"Channel Classification Not Supported",	"Insufficient Security",	"Parameter out of Mandatory Range",	"Reserved",	"Role Switch Pending",	"Reserved",	"Reserved Slot Violation",	"Role Switch Failed",	"Extended Inquiry Response Too Large",	"Simple Pairing Not Supported by Host",	"Host Busy - Pairing",};static char *status2str(uint8_t status){	char *str;	if (status <= ERROR_CODE_NUM)		str = error_code_str[status];	else		str = "Unknown";	return str;}static char *opcode2str(uint16_t opcode){	uint16_t ogf = cmd_opcode_ogf(opcode);	uint16_t ocf = cmd_opcode_ocf(opcode);	char *cmd;	switch (ogf) {	case OGF_INFO_PARAM:		if (ocf <= CMD_INFO_NUM)			cmd = cmd_info_str[ocf];		else			cmd = "Unknown";		break;	case OGF_HOST_CTL:		if (ocf <= CMD_HOSTCTL_NUM)			cmd = cmd_hostctl_str[ocf];		else			cmd = "Unknown";		break;	case OGF_LINK_CTL:		if (ocf <= CMD_LINKCTL_NUM)			cmd = cmd_linkctl_str[ocf];		else			cmd = "Unknown";		break;	case OGF_LINK_POLICY:		if (ocf <= CMD_LINKPOL_NUM)			cmd = cmd_linkpol_str[ocf];		else			cmd = "Unknown";		break;	case OGF_STATUS_PARAM:		if (ocf <= CMD_STATUS_NUM)			cmd = cmd_status_str[ocf];		else			cmd = "Unknown";		break;	case OGF_TESTING_CMD:		if (ocf <= CMD_TESTING_NUM)			cmd = cmd_testing_str[ocf];		else			cmd = "Unknown";		break;	case OGF_VENDOR_CMD:		cmd = "Vendor";		break;	default:		cmd = "Unknown";		break;	}	return cmd;}static char *role2str(uint8_t role){	switch (role) {	case 0x00:		return "Master";	case 0x01:		return "Slave";	default:		return "Unknown";	}}static char *mode2str(uint8_t mode){	switch (mode) {	case 0x00:		return "Active";	case 0x01:		return "Hold";	case 0x02:		return "Sniff";	case 0x03:		return "Park";	default:		return "Unknown";	}}static char *airmode2str(uint8_t mode){	switch (mode) {	case 0x00:		return "u-law log";	case 0x01:		return "A-law log";	case 0x02:		return "CVSD";	case 0x04:		return "Transparent data";	default:		return "Reserved";	}}static char *keytype2str(uint8_t type){	switch (type) {	case 0x00:		return "Combination Key";	case 0x01:		return "Local Unit Key";	case 0x02:		return "Remote Unit Key";	case 0x03:		return "Debug Combination Key";	case 0x04:		return "Unauthenticated Combination Key";	case 0x05:		return "Authenticated Combination Key";	case 0x06:		return "Changed Combination Key";	default:		return "Reserved";	}}static char *capability2str(uint8_t capability){	switch (capability) {	case 0x00:		return "DisplayOnly";	case 0x01:		return "DisplayYesNo";	case 0x02:		return "KeyboardOnly";	case 0x03:		return "NoInputNoOutput";	default:		return "Reserved";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -