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

📄 hciconfig.c

📁 Bluezan implementation of the Bluetooth&#8482 wireless standards specifications for Linux. The code
💻 C
📖 第 1 页 / 共 3 页
字号:
			return "Cellular";		case 2:			return "Cordless";		case 3:			return "Smart phone";		case 4:			return "Wired modem or voice gateway";		case 5:			return "Common ISDN Access";		case 6:			return "Sim Card Reader";		}		break;	case 3:	/* lan access */		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];	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");	}	hci_close_dev(dd);}static void cmd_version(int ctl, int hdev, char *opt){	struct hci_version ver;	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);	}	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",		hci_vertostr(ver.hci_ver), ver.hci_ver, ver.hci_rev,		lmp_vertostr(ver.lmp_ver), ver.lmp_ver, ver.lmp_subver,		bt_compidtostr(ver.manufacturer), ver.manufacturer);	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: %s\n",			mode == 1 ? "Inquiry with RSSI" : "Standard Inquiry");	}}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");	}}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",						hdev, strerror(errno), errno);		exit(1);	}	memset(&rq, 0, sizeof(rq));	if (opt) {		unsigned int window, interval;		write_inq_activity_cp cp;		if (sscanf(opt,"%4u:%4u", &window, &interval) != 2) {			printf("Invalid argument format\n");			exit(1);		}		rq.ogf = OGF_HOST_CTL;		rq.ocf = OCF_WRITE_INQ_ACTIVITY;		rq.cparam = &cp;		rq.clen = WRITE_INQ_ACTIVITY_CP_SIZE;		cp.window = htobs((uint16_t) window);		cp.interval = htobs((uint16_t) interval);		if (window < 0x12 || window > 0x1000)			printf("Warning: inquiry window out of range!\n");		if (interval < 0x12 || interval > 0x1000)			printf("Warning: inquiry interval out of range!\n");		if (hci_send_req(s, &rq, 2000) < 0) {			fprintf(stderr, "Can't set inquiry parameters name on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}	} else {		uint16_t window, interval;		read_inq_activity_rp rp;		rq.ogf = OGF_HOST_CTL;		rq.ocf = OCF_READ_INQ_ACTIVITY;		rq.rparam = &rp;		rq.rlen = READ_INQ_ACTIVITY_RP_SIZE;		if (hci_send_req(s, &rq, 1000) < 0) {			fprintf(stderr, "Can't read inquiry parameters on hci%d: %s (%d)\n",						hdev, strerror(errno), errno);			exit(1);		}

⌨️ 快捷键说明

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