?? hciconfig.c
字號:
case 3: strncat(cls_str, "Remote control", sizeof(cls_str) - strlen(cls_str)); break; case 4: strncat(cls_str, "Sensing device", sizeof(cls_str) - strlen(cls_str)); break; case 5: strncat(cls_str, "Digitizer tablet", sizeof(cls_str) - strlen(cls_str)); break; case 6: strncat(cls_str, "Card reader", sizeof(cls_str) - strlen(cls_str)); break; default: strncat(cls_str, "(reserved)", sizeof(cls_str) - strlen(cls_str)); break; } if(strlen(cls_str) > 0) return cls_str; } 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 7: /* wearable */ switch(minor) { case 1: return "Wrist Watch"; case 2: return "Pager"; case 3: return "Jacket"; case 4: return "Helmet"; case 5: return "Glasses"; } break; case 8: /* toy */ switch(minor) { case 1: return "Robot"; case 2: return "Vehicle"; case 3: return "Doll / Action Figure"; case 4: return "Controller"; case 5: return "Game"; } break; case 63: /* uncategorised */ return ""; } return "Unknown (reserved) minor device class";}static void cmd_class(int ctl, int hdev, char *opt){ static const char *services[] = { "Positioning", "Networking", "Rendering", "Capturing", "Object Transfer", "Audio", "Telephony", "Information" }; static const 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) / sizeof(*services)); s++) if (cls[2] & (1 << s)) { if (!first) printf(", "); printf("%s", services[s]); first = 0; } } else printf("Unspecified"); printf("\n\tDevice Class: "); if ((cls[1] & 0x1f) >= sizeof(major_devices) / 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); create_name(filename, PATH_MAX, STORAGEDIR, addr, "linkkeys"); 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_oob_data(int ctl, int hdev, char *opt){ uint8_t hash[16], randomizer[16]; 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 (hci_read_local_oob_data(dd, hash, randomizer, 1000) < 0) { fprintf(stderr, "Can't read local OOB data on hci%d: %s (%d)\n", hdev, strerror(errno), errno); exit(1); } print_dev_hdr(&di); printf("\tOOB Hash: "); for (i = 0; i < 16; i++) printf(" %02x", hash[i]); printf("\n\tRandomizer:"); for (i = 0; i < 16; i++) printf(" %02x", randomizer[i]); printf("\n"); 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 (cmds[i] & (1 << n)) 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_tpl(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) { int8_t level = atoi(opt); if (hci_write_inquiry_transmit_power_level(dd, level, 2000) < 0) { fprintf(stderr, "Can't set inquiry transmit power level on hci%d: %s (%d)\n", hdev, strerror(errno), errno); exit(1); } } else { int8_t level; if (hci_read_inquiry_transmit_power_level(dd, &level, 1000) < 0) { fprintf(stderr, "Can't read inquiry transmit power level on hci%d: %s (%d)\n", hdev, strerror(errno), errno); exit(1); } print_dev_hdr(&di); printf("\tInquiry transmit power level: %d\n", level); } 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 0x01: printf("\tFlags:"); for (i = 0; i < len - 1; i++) printf(" 0x%2.2x", *((uint8_t *) (ptr + i))); printf("\n"); break; case 0x02: case 0x03: printf("\t%s service classes:", type == 0x02 ? "Shortened" : "Complete"); for (i = 0; i < (len - 1) / 2; i++) { uint16_t val = btohs(bt_get_unaligned((uint16_t *) (ptr + (i * 2)))); printf(" 0x%4.4x", val); } printf("\n"); break; case 0x08: case 0x09: str = malloc(len); if (str) { snprintf(str, len, "%s", ptr); for (i = 0; i < len - 1; i++) { if ((unsigned char) str[i] < 32 || str[i] == 127) str[i] = '.'; } printf("\t%s local name: \'%s\'\n", type == 0x08 ? "Shortened" : "Complete", str); free(str); } break; case 0x0a: printf("\tTX power level: %d\n", *((uint8_t *) ptr)); 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);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -