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

📄 hciconfig.c

📁 蓝牙bluez-utils-2.25.tar.gz网上很少找到这个版本的了
💻 C
📖 第 1 页 / 共 3 页
字号:
		if (minor == 0)			return "Uncategorized";		switch(minor / 8) {		case 0:			return "Fully available";		case 1:			return "1-17% utilized";		case 2:			return "17-33% utilized";		case 3:			return "33-50% utilized";		case 4:			return "50-67% utilized";		case 5:			return "67-83% utilized";		case 6:			return "83-99% utilized";		case 7:			return "No service available";		}		break;	case 4:	/* audio/video */		switch(minor) {		case 0:			return "Uncategorized";		case 1:			return "Device conforms to the Headset profile";		case 2:			return "Hands-free";			/* 3 is reserved */		case 4:			return "Microphone";		case 5:			return "Loudspeaker";		case 6:			return "Headphones";		case 7:			return "Portable Audio";		case 8:			return "Car Audio";		case 9:			return "Set-top box";		case 10:			return "HiFi Audio Device";		case 11:			return "VCR";		case 12:			return "Video Camera";		case 13:			return "Camcorder";		case 14:			return "Video Monitor";		case 15:			return "Video Display and Loudspeaker";		case 16:			return "Video Conferencing";			/* 17 is reserved */		case 18:			return "Gaming/Toy";		}		break;	case 5:	/* peripheral */		switch(minor) {		case 16:			return "Keyboard";		case 32:			return "Pointing device";		case 48:			return "Combo keyboard/pointing device";		}		break;	case 6:	/* imaging */		if (minor & 4)			return "Display";		if (minor & 8)			return "Camera";		if (minor & 16)			return "Scanner";		if (minor & 32)			return "Printer";		break;	case 63:	/* uncategorised */		return "";	}	return "Unknown (reserved) minor device class";}static void cmd_class(int ctl, int hdev, char *opt){	static char *services[] = { "Positioning",					"Networking",					"Rendering",					"Capturing",					"Object Transfer",					"Audio",					"Telephony",					"Information" };	static char *major_devices[] = { "Miscellaneous",					"Computer",					"Phone",					"LAN Access",					"Audio/Video",					"Peripheral",					"Imaging",					"Uncategorized" };	int s = hci_open_dev(hdev);	if (s < 0) {		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	if (opt) {		uint32_t cod = strtoul(opt, NULL, 16);		if (hci_write_class_of_dev(s, cod, 2000) < 0) {			fprintf(stderr, "Can't write local class of device on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}	} else {		uint8_t cls[3];		if (hci_read_class_of_dev(s, cls, 1000) < 0) {			fprintf(stderr, "Can't read class of device on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}		print_dev_hdr(&di);		printf("\tClass: 0x%02x%02x%02x\n", cls[2], cls[1], cls[0]);		printf("\tService Classes: ");		if (cls[2]) {			int first = 1;			for (s = 0; s < sizeof(*services); s++)				if (cls[2] & (1 << s)) {					if (!first)						printf(", ");					printf(services[s]);					first = 0;				}		} else			printf("Unspecified");		printf("\n\tDevice Class: ");		if ((cls[1] & 0x1f) > sizeof(*major_devices))			printf("Invalid Device Class!\n");		else			printf("%s, %s\n", major_devices[cls[1] & 0x1f],				get_minor_device_name(cls[1] & 0x1f, cls[0] >> 2));	}}static void cmd_voice(int ctl, int hdev, char *opt){	static char *icf[] = { "Linear", "u-Law", "A-Law", "Reserved" };	static char *idf[] = { "1's complement", "2's complement", "Sign-Magnitude", "Reserved" };	static char *iss[] = { "8 bit", "16 bit" };	static char *acf[] = { "CVSD", "u-Law", "A-Law", "Reserved" };	int s = hci_open_dev(hdev);	if (s < 0) {		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	if (opt) {		uint16_t vs = htobs(strtoul(opt, NULL, 16));		if (hci_write_voice_setting(s, vs, 2000) < 0) {			fprintf(stderr, "Can't write voice setting on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}	} else {		uint16_t vs;		uint8_t ic;		if (hci_read_voice_setting(s, &vs, 1000) < 0) {			fprintf(stderr, "Can't read voice setting on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}		vs = htobs(vs);		ic = (vs & 0x0300) >> 8;		print_dev_hdr(&di);		printf("\tVoice setting: 0x%04x%s\n", vs,			((vs & 0x03fc) == 0x0060) ? " (Default Condition)" : "");		printf("\tInput Coding: %s\n", icf[ic]);		printf("\tInput Data Format: %s\n", idf[(vs & 0xc0) >> 6]);		if (!ic) {			printf("\tInput Sample Size: %s\n", iss[(vs & 0x20) >> 5]);			printf("\t# of bits padding at MSB: %d\n", (vs & 0x1c) >> 2);		}		printf("\tAir Coding Format: %s\n", acf[vs & 0x03]);	}}static int get_link_key(const bdaddr_t *local, const bdaddr_t *peer, uint8_t *key){	char filename[PATH_MAX + 1], addr[18], tmp[3], *str;	int i;	ba2str(local, addr);	snprintf(filename, PATH_MAX, "%s/%s/linkkeys", STORAGEDIR, addr);	ba2str(peer, addr);	str = textfile_get(filename, addr);	if (!str)		return -EIO;	memset(tmp, 0, sizeof(tmp));	for (i = 0; i < 16; i++) {		memcpy(tmp, str + (i * 2), 2);		key[i] = (uint8_t) strtol(tmp, NULL, 16);	}	free(str);	return 0;}static void cmd_putkey(int ctl, int hdev, char *opt){	struct hci_dev_info di;	bdaddr_t bdaddr;	uint8_t key[16];	int dd;	if (!opt)		return;	dd = hci_open_dev(hdev);	if (dd < 0) {		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	if (hci_devinfo(hdev, &di) < 0) {		fprintf(stderr, "Can't get device info for hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	str2ba(opt, &bdaddr);	if (get_link_key(&di.bdaddr, &bdaddr, key) < 0) {		fprintf(stderr, "Can't find link key for %s on hci%d\n", opt, hdev);		exit(1);	}	if (hci_write_stored_link_key(dd, &bdaddr, key, 1000) < 0) {		fprintf(stderr, "Can't write stored link key on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	hci_close_dev(dd);}static void cmd_delkey(int ctl, int hdev, char *opt){	bdaddr_t bdaddr;	uint8_t all;	int dd;	if (!opt)		return;	dd = hci_open_dev(hdev);	if (dd < 0) {		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	if (!strcasecmp(opt, "all")) {		bacpy(&bdaddr, BDADDR_ANY);		all = 1;	} else {		str2ba(opt, &bdaddr);		all = 0;	}	if (hci_delete_stored_link_key(dd, &bdaddr, all, 1000) < 0) {		fprintf(stderr, "Can't delete stored link key on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	hci_close_dev(dd);}static void cmd_commands(int ctl, int hdev, char *opt){	uint8_t cmds[64];	char *str;	int i, n, dd;	dd = hci_open_dev(hdev);	if (dd < 0) {		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	if (hci_read_local_commands(dd, cmds, 1000) < 0) {		fprintf(stderr, "Can't read support commands on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	print_dev_hdr(&di);	for (i = 0; i < 64; i++) {		if (!cmds[i])			continue;		printf("%s Octet %-2d = 0x%02x (Bit",			i ? "\t\t ": "\tCommands:", i, cmds[i]);		for (n = 0; n < 8; n++)			if (hci_test_bit(n, &cmds[i]))				printf(" %d", n);		printf(")\n");	}	str = hci_commandstostr(cmds, "\t", 71);	printf("%s\n", str);	bt_free(str);	hci_close_dev(dd);}static void cmd_version(int ctl, int hdev, char *opt){	struct hci_version ver;	char *hciver, *lmpver;	int dd;	dd = hci_open_dev(hdev);	if (dd < 0) {		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	if (hci_read_local_version(dd, &ver, 1000) < 0) {		fprintf(stderr, "Can't read version info hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	hciver = hci_vertostr(ver.hci_ver);	lmpver = lmp_vertostr(ver.hci_ver);	print_dev_hdr(&di);	printf("\tHCI Ver: %s (0x%x) HCI Rev: 0x%x LMP Ver: %s (0x%x) LMP Subver: 0x%x\n"		"\tManufacturer: %s (%d)\n",		hciver ? hciver : "n/a", ver.hci_ver, ver.hci_rev,		lmpver ? lmpver : "n/a", ver.lmp_ver, ver.lmp_subver,		bt_compidtostr(ver.manufacturer), ver.manufacturer);	if (hciver)		bt_free(hciver);	if (lmpver)		bt_free(lmpver);	hci_close_dev(dd);}static void cmd_inq_mode(int ctl, int hdev, char *opt){	int dd;	dd = hci_open_dev(hdev);	if (dd < 0) {		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	if (opt) {		uint8_t mode = atoi(opt);		if (hci_write_inquiry_mode(dd, mode, 2000) < 0) {			fprintf(stderr, "Can't set inquiry mode on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}	} else {		uint8_t mode;		if (hci_read_inquiry_mode(dd, &mode, 1000) < 0) {			fprintf(stderr, "Can't read inquiry mode on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}		print_dev_hdr(&di);		printf("\tInquiry mode: ");		switch (mode) {		case 0:			printf("Standard Inquiry\n");			break;		case 1:			printf("Inquiry with RSSI\n");			break;		case 2:			printf("Inquiry with RSSI or Extended Inquiry\n");			break;		default:			printf("Unknown (0x%02x)\n", mode);			break;		}	}	hci_close_dev(dd);}static void cmd_inq_data(int ctl, int hdev, char *opt){	int i, dd;	dd = hci_open_dev(hdev);	if (dd < 0) {		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	if (opt) {		uint8_t fec = 0, data[240];		char tmp[3];		int i, size;		memset(data, 0, sizeof(data));		memset(tmp, 0, sizeof(tmp));		size = (strlen(opt) + 1) / 2;		if (size > 240)			size = 240;		for (i = 0; i < size; i++) {			memcpy(tmp, opt + (i * 2), 2);			data[i] = strtol(tmp, NULL, 16);		}		if (hci_write_ext_inquiry_response(dd, fec, data, 2000) < 0) {			fprintf(stderr, "Can't set extended inquiry response on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}	} else {		uint8_t fec, data[240], len, type, *ptr;		char *str;		if (hci_read_ext_inquiry_response(dd, &fec, data, 1000) < 0) {			fprintf(stderr, "Can't read extended inquiry response on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}		print_dev_hdr(&di);		printf("\tFEC %s\n\t\t", fec ? "enabled" : "disabled");		for (i = 0; i < 240; i++)			printf("%02x%s%s", data[i], (i + 1) % 8 ? "" : " ",				(i + 1) % 16 ? " " : (i < 239 ? "\n\t\t" : "\n"));		ptr = data;		while (*ptr) {			len = *ptr++;			type = *ptr++;			switch (type) {			case 0x08:			case 0x09:				str = malloc(len);				if (str) {					snprintf(str, len, "%s", ptr);					for (i = 0; i < len - 1; i++)						if (!isprint(str[i]))							str[i] = '.';					printf("\t%s local name: \'%s\'\n",						type == 0x08 ? "Shortened" : "Complete", str);					free(str);				}				break;			default:				printf("\tUnknown type 0x%02x with %d bytes data\n",								type, len - 1);				break;			}			ptr += (len - 1);		}		printf("\n");	}	hci_close_dev(dd);}static void cmd_inq_type(int ctl, int hdev, char *opt){	int dd;	dd = hci_open_dev(hdev);	if (dd < 0) {		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",						hdev, strerror(errno), errno);		exit(1);	}	if (opt) {		uint8_t type = atoi(opt);		if (hci_write_inquiry_scan_type(dd, type, 2000) < 0) {			fprintf(stderr, "Can't set inquiry scan type on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}	} else {		uint8_t type;		if (hci_read_inquiry_scan_type(dd, &type, 1000) < 0) {			fprintf(stderr, "Can't read inquiry scan type on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}		print_dev_hdr(&di);		printf("\tInquiry scan type: %s\n",			type == 1 ? "Interlaced Inquiry Scan" : "Standard Inquiry Scan");	}	hci_close_dev(dd);}static void cmd_inq_parms(int ctl, int hdev, char *opt){	struct hci_request rq;	int s;	if ((s = hci_open_dev(hdev)) < 0) {		fprintf(stderr, "Can't open device hci%d: %s (%d)\n",

⌨️ 快捷键说明

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